home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / network / ncsasock / s_socket.h < prev    next >
Text File  |  1996-07-05  |  8KB  |  226 lines

  1. /*
  2.  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution is only permitted until one year after the first shipment
  6.  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
  7.  * binary forms are permitted provided that: (1) source distributions retain
  8.  * this entire copyright notice and comment, and (2) distributions including
  9.  * binaries display the following acknowledgement:  This product includes
  10.  * software developed by the University of California, Berkeley and its
  11.  * contributors'' in the documentation or other materials provided with the
  12.  * distribution and in all advertising materials mentioning features or use
  13.  * of this software.  Neither the name of the University nor the names of
  14.  * its contributors may be used to endorse or promote products derived from
  15.  * this software without specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  *
  20.  *    @(#)socket.h    7.10 (Berkeley) 6/28/90
  21.  */
  22.  
  23. /*
  24.  * Definitions related to sockets: types, address families, options.
  25.  */
  26.  
  27. /*
  28.  * Types
  29.  */
  30. #define    SOCK_STREAM    1        /* stream socket */
  31. #define    SOCK_DGRAM    2        /* datagram socket */
  32. #define    SOCK_RAW    3        /* raw-protocol interface */
  33. #define    SOCK_RDM    4        /* reliably-delivered message */
  34. #define    SOCK_SEQPACKET    5        /* sequenced packet stream */
  35.  
  36. /*
  37.  * Option flags per-socket.
  38.  */
  39. #define    SO_DEBUG    0x0001        /* turn on debugging info recording */
  40. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  41. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  42. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  43. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  44. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  45. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  46. #define    SO_LINGER    0x0080        /* linger on close if data present */
  47. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  48.  
  49. /*
  50.  * Additional options, not kept in so_options.
  51.  */
  52. #define SO_SNDBUF    0x1001        /* send buffer size */
  53. #define SO_RCVBUF    0x1002        /* receive buffer size */
  54. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  55. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  56. #define SO_SNDTIMEO    0x1005        /* send timeout */
  57. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  58. #define    SO_ERROR    0x1007        /* get error status and clear */
  59. #define    SO_TYPE        0x1008        /* get socket type */
  60.  
  61. /*
  62.  * Structure used for manipulating linger option.
  63.  */
  64. struct    linger {
  65.     Int4    l_onoff;        /* option on/off */
  66.     Int4    l_linger;        /* linger time */
  67. };
  68.  
  69. /*
  70.  * Level number for (get/set)sockopt() to apply to socket itself.
  71.  */
  72. #define    SOL_SOCKET    0xffff        /* options for socket level */
  73.  
  74. /*
  75.  * Address families.
  76.  */
  77. #define    AF_UNSPEC    0        /* unspecified */
  78. #define    AF_UNIX        1        /* local to host (pipes, portals) */
  79. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  80. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  81. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  82. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  83. #define    AF_NS        6        /* XEROX NS protocols */
  84. #define    AF_ISO        7        /* ISO protocols */
  85. #define    AF_OSI        AF_ISO
  86. #define    AF_ECMA        8        /* european computer manufacturers */
  87. #define    AF_DATAKIT    9        /* datakit protocols */
  88. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  89. #define    AF_SNA        11        /* IBM SNA */
  90. #define AF_DECnet    12        /* DECnet */
  91. #define AF_DLI        13        /* DEC Direct data link interface */
  92. #define AF_LAT        14        /* LAT */
  93. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  94. #define    AF_APPLETALK    16        /* Apple Talk */
  95. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  96. #define    AF_LINK        18        /* Link layer interface */
  97. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  98.  
  99. #define    AF_MAX        20
  100.  
  101. /*
  102.  * Structure used by kernel to store most
  103.  * addresses.
  104.  */
  105. struct sockaddr {
  106.     u_char    sa_len;            /* total length */
  107.     u_char    sa_family;        /* address family */
  108.     char    sa_data[14];        /* actually longer; address value */
  109. };
  110.  
  111. /*
  112.  * Structure used by kernel to pass protocol
  113.  * information in raw sockets.
  114.  */
  115. struct sockproto {
  116.     u_short    sp_family;        /* address family */
  117.     u_short    sp_protocol;        /* protocol */
  118. };
  119.  
  120. /*
  121.  * Protocol families, same as address families for now.
  122.  */
  123. #define    PF_UNSPEC    AF_UNSPEC
  124. #define    PF_UNIX        AF_UNIX
  125. #define    PF_INET        AF_INET
  126. #define    PF_IMPLINK    AF_IMPLINK
  127. #define    PF_PUP        AF_PUP
  128. #define    PF_CHAOS    AF_CHAOS
  129. #define    PF_NS        AF_NS
  130. #define    PF_ISO        AF_ISO
  131. #define    PF_OSI        AF_ISO
  132. #define    PF_ECMA        AF_ECMA
  133. #define    PF_DATAKIT    AF_DATAKIT
  134. #define    PF_CCITT    AF_CCITT
  135. #define    PF_SNA        AF_SNA
  136. #define PF_DECnet    AF_DECnet
  137. #define PF_DLI        AF_DLI
  138. #define PF_LAT        AF_LAT
  139. #define    PF_HYLINK    AF_HYLINK
  140. #define    PF_APPLETALK    AF_APPLETALK
  141. #define    PF_ROUTE    AF_ROUTE
  142. #define    PF_LINK        AF_LINK
  143. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  144.  
  145. #define    PF_MAX        AF_MAX
  146.  
  147. /*
  148.  * Maximum queue length specifiable by listen.
  149.  */
  150. #define    SOMAXCONN    5
  151.  
  152. /*
  153.  * Message header for recvmsg and sendmsg calls.
  154.  * Used value-result for recvmsg, value only for sendmsg.
  155.  */
  156.  
  157. /*
  158.  * Macintosh needs 4.3 compatible headers for DTM. At the end of the file.
  159.  */
  160.  
  161. // struct msghdr {
  162. //    caddr_t    msg_name;        /* optional address */
  163. //    u_int    msg_namelen;        /* size of address */
  164. //    struct    iovec *msg_iov;        /* scatter/gather array */
  165. //    u_int    msg_iovlen;        /* # elements in msg_iov */
  166. //    caddr_t    msg_control;        /* ancillary data, see below */
  167. //    u_int    msg_controllen;        /* ancillary data buffer len */
  168. //    int    msg_flags;        /* flags on received message */
  169. // };
  170.  
  171. #define    MSG_OOB        0x1        /* process out-of-band data */
  172. #define    MSG_PEEK    0x2        /* peek at incoming message */
  173. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  174. #define    MSG_EOR        0x8        /* data completes record */
  175. #define    MSG_TRUNC    0x10        /* data discarded before delivery */
  176. #define    MSG_CTRUNC    0x20        /* control data lost before delivery */
  177. #define    MSG_WAITALL    0x40        /* wait for full request or error */
  178.  
  179. /*
  180.  * Header for ancillary data objects in msg_control buffer.
  181.  * Used for additional information with/about a datagram
  182.  * not expressible by flags.  The format is a sequence
  183.  * of message elements headed by cmsghdr structures.
  184.  */
  185. struct cmsghdr {
  186.     u_int    cmsg_len;        /* data byte count, including hdr */
  187.     int    cmsg_level;        /* originating protocol */
  188.     int    cmsg_type;        /* protocol-specific type */
  189. /* followed by    u_char  cmsg_data[]; */
  190. };
  191.  
  192. /* given pointer to struct adatahdr, return pointer to data */
  193. #define    CMSG_DATA(cmsg)        ((u_char *)((cmsg) + 1))
  194.  
  195. /* given pointer to struct adatahdr, return pointer to next adatahdr */
  196. #define    CMSG_NXTHDR(mhdr, cmsg)    \
  197.     (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  198.         (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  199.         (struct cmsghdr *)NULL : \
  200.         (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  201.  
  202. #define    CMSG_FIRSTHDR(mhdr)    ((struct cmsghdr *)(mhdr)->msg_control)
  203.  
  204. /* "Socket"-level control message types: */
  205. #define    SCM_RIGHTS    0x01        /* access rights (array of int) */
  206.  
  207. /*
  208.  * 4.3 compat sockaddr, move to compat file later
  209.  */
  210. struct osockaddr {
  211.     u_short    sa_family;        /* address family */
  212.     char    sa_data[14];        /* up to 14 bytes of direct address */
  213. };
  214.  
  215. /*
  216.  * 4.3-compat message header (move to compat file later).
  217.  */
  218. struct msghdr {
  219.     caddr_t    msg_name;        /* optional address */
  220.     Int4    msg_namelen;        /* size of address */
  221.     struct    iovec *msg_iov;        /* scatter/gather array */
  222.     Int4    msg_iovlen;        /* # elements in msg_iov */
  223.     caddr_t    msg_accrights;        /* access rights sent/received */
  224.     Int4    msg_accrightslen;
  225. };
  226.